#
# @lc app=leetcode.cn id=122 lang=python3
#
# [122] 买卖股票的最佳时机 II
#

# @lc code=start
class Solution:
    def maxProfit(self, prices: List[int]) -> int:
        maxP = 0
        numList = len(prices)
        preIndex = 0
        curIndex = 1
        
        
        while curIndex < numList:
            if prices[curIndex] < prices[curIndex - 1]:
                maxP += prices[curIndex - 1] - prices[preIndex]
                preIndex = curIndex
            curIndex += 1

        maxP = max(maxP, maxP + prices[numList - 1] - prices[preIndex])
        
        return maxP
# @lc code=end

